﻿// -----------------------------
// Copyright © Kodi Studios 2012
// -----------------------------

using System;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Reflection;

namespace Kodi.PicturethrillUpdateServiceTest
{
    class Program
    {
        static void Main(string[] args)
        {
            using (UpdateServiceClient updateServiceClient = new UpdateServiceClient())
            {
                FileVersionInfo picturethrillFileVersionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
                Version expectedLatestVersion = new Version(picturethrillFileVersionInfo.ProductVersion);

                Version latestVersion = updateServiceClient.GetLatestVersion();
                Console.WriteLine("Latest Version: " + latestVersion);
                Console.WriteLine("Latest Version Correct: " + (expectedLatestVersion == latestVersion));

                string setupUrl = updateServiceClient.GetSetupUrl(latestVersion);
                Console.WriteLine("Setup Url: " + setupUrl);

                string testDirectory = Path.Combine(Path.GetTempPath(), "Test");
                if (!Directory.Exists(testDirectory))
                {
                    Directory.CreateDirectory(testDirectory);
                }

                string picturethrillSetupPath = Path.Combine(testDirectory, "PicturethrillSetup.exe");
                using (WebClient webClient = new WebClient())
                {
                    webClient.DownloadFile(setupUrl, picturethrillSetupPath);
                }
                Console.WriteLine("File downloaded successfully: " + File.Exists(picturethrillSetupPath));
            }

            // Launch picturethrill update

            //Process.Start(@"C:\Users\niko\AppData\Local\Aristov\Picturethrill\PicturethrillUpdate.exe", "-url http://picturethrill.com/Downloads/v2.5.1.1/PicturethrillSetup.exe");

            // Run Update Service.
            //PicturethrillUpdateTask updateTask = new PicturethrillUpdateTask();
            //updateTask.RunTask();
        }
    }
}
